package com.toe.forum.webapi.controller;


import com.toe.common.restful.JsonPage;
import com.toe.common.restful.JsonResult;
import com.toe.forum.service.ForumUserLikeService;
import com.toe.pojo.dto.forum.UserLikeAddDTO;
import com.toe.pojo.dto.forum.UserLikeUpdateDTO;
import com.toe.pojo.vo.forum.UserLIkeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * <p>
 * 点赞用户映射表 前端控制器
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */
@RestController
@RequestMapping("/forum-user-like")
@Api(tags = "用户点赞文章映射模块")
public class ForumUserLikeController {

    @Autowired
    private ForumUserLikeService forumUserLikeService;

    @ApiOperation("新增用户点赞文章映射")
    @PostMapping("/insert")
    public JsonResult<Void> insert(@RequestBody UserLikeAddDTO userLikeAddDTO){
        forumUserLikeService.insert(userLikeAddDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除用户点赞文章映射")
    @PostMapping("/delete/{id}")
    public JsonResult<Void> delete(@PathVariable long id){
        forumUserLikeService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("删除指定点赞文章映射")
    @PostMapping("/delete")
    public JsonResult<Void> deleteUserLike(long userId,long articleId){
        forumUserLikeService.deleteUserLike(userId, articleId);
        return JsonResult.ok();
    }

//    @ApiOperation("更新用户点赞文章映射")
//    @PostMapping("/update")
//    public JsonResult<Void> update(UserLikeUpdateDTO userLikeUpdateDTO){
//        forumUserLikeService.updateUserLike(userLikeUpdateDTO);
//        return JsonResult.ok();
//    }

//    @ApiOperation("查询所有用户点赞文章映射")
//    @GetMapping("/select/list")
//    public JsonResult<List<UserLIkeVO>> selectAllUserLike(){
//        List<UserLIkeVO> userLIkeVOS = forumUserLikeService.selectAllUserLike();
//        return JsonResult.ok(userLIkeVOS);
//    }

//    @ApiOperation("分页查询所有的用户点赞文章映射")
//    @GetMapping("/select/list/page")
//    public JsonResult<JsonPage<UserLIkeVO>> selectAllUserLikePage(Integer pageNum,Integer pageSize){
//        JsonPage<UserLIkeVO> userLIkeVOJsonPage = forumUserLikeService.selectAllUserLikePage(pageNum,pageSize);
//        return JsonResult.ok(userLIkeVOJsonPage);
//    }

//    @ApiOperation("查询对应文章ID的文章的所有点赞映射")
//    @GetMapping("/select/article/{articleId}")
//    public JsonResult<List<UserLIkeVO>> selectAllUserLikeByArticleId(@PathVariable long articleId){
//        List<UserLIkeVO> userLIkeVOS = forumUserLikeService.selectAllUserLikeByArticleId(articleId);
//        return JsonResult.ok(userLIkeVOS);
//    }

//    @ApiOperation("分页查询对应文章ID的文章的所有点赞映射")
//    @GetMapping("/select/article/{articleId}/page")
//    public JsonResult<JsonPage<UserLIkeVO>> selectAllUserLikeByArticleIdPage(@PathVariable long articleId,Integer pageNum,Integer pageSize){
//        JsonPage<UserLIkeVO> userLIkeVOJsonPage = forumUserLikeService.selectAllUserLikeByArticleIdPage(articleId, pageNum, pageSize);
//        return JsonResult.ok(userLIkeVOJsonPage);
//    }

    @ApiOperation("查询某条用户点赞文章映射是否存在")
    @GetMapping("/select/one")
    public JsonResult<Boolean> selectOneUserLike(long userId,long articleId){
        Boolean aBoolean = forumUserLikeService.selectOneUserLike(userId, articleId);
        return JsonResult.ok(aBoolean);
    }
}

